package com.qk.management.controller;

import com.qk.common.Result;
import com.qk.dto.customer.CustomerQueryDTO;
import com.qk.entity.Customer;
import com.qk.management.anno.LogOperation;
import com.qk.management.service.CustomerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 16778
 * @date 2025/10/15 11:24
 * @description
 */
@Slf4j
@RestController
@RequestMapping("/customers")
public class CustomerController {

    @Autowired
    private CustomerService customerService;

    @GetMapping
    public Result page(CustomerQueryDTO dto){
        return Result.success(customerService.selectByPage(dto));
    }

    @LogOperation
    @PostMapping
    public Result save(@RequestBody Customer customer){
        customerService.insert(customer);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result get(@PathVariable Integer id){
        return Result.success(customerService.getById(id));
    }

    @LogOperation
    @PutMapping
    public Result update(@RequestBody Customer customer){
        customerService.updateById(customer);
        return Result.success();
    }
}
